export const parseToken = (token) => {
    if (!token) return null

    try {
        // 截取payload部分
        const payload = token.split('.')[1]
        // Base64解码
        const decoded = atob(payload.replace(/-/g, '+').replace(/_/g, '/'))
        return JSON.parse(decoded)
    } catch (e) {
        console.error('Token解析失败:', e)
        return null
    }
}

// 新增获取用户名方法
export const getUsernameFromToken = (token) => {
    const payload = parseToken(token)
    return payload?.username || '未知用户'
}